Skip to content

Fix NPY header length error due to signed->unsigned conversion#2889

Open
Kwonunn wants to merge 1 commit intoxtensor-stack:masterfrom
Kwonunn:npy-header-fix
Open

Fix NPY header length error due to signed->unsigned conversion#2889
Kwonunn wants to merge 1 commit intoxtensor-stack:masterfrom
Kwonunn:npy-header-fix

Conversation

@Kwonunn
Copy link
Copy Markdown

@Kwonunn Kwonunn commented Apr 3, 2026

Checklist

  • The title and commit message(s) are descriptive.
  • Small commits made to fix your PR have been squashed to avoid history pollution.
  • Tests have been added for new features or bug fixes.
  • API of new functions and classes are documented.

Description

This PR fixes an error pertaining to reading the length of the header of an npy file. The header is read as two chars and then combined into a uint16_t. Previously due to char being a signed value, any value with the MSB set would get converted as if it were a negative number and thus misinterpreted.

For example, the bytes F6 00 which means a header of 246 bytes would be interpreted as a header of 65526 bytes.

I think the code could be shortened a little, but I think when messing with bits like this it's best to be explicit. Also, the compiler will likely optimize it anyway.

@Kwonunn Kwonunn changed the title Fix header length error due to signed->unsigned conversion Fix NPY header length error due to signed->unsigned conversion Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant